﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using ExtAspNet;
using System.Data;
using Ylh.BLL;

public partial class Module_CustManger_CustInfo : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BtnCancel.OnClientClick = ActiveWindow.GetHideReference();

        if (!IsPostBack)
        {
            ShowInfo(Convert.ToInt32(Request.QueryString["CustID"].ToString()));
            LoadFlowData(Request.QueryString["CustID"].ToString());
            LoadMetData(Request.QueryString["CustID"].ToString());

            LoadOpinion(Request.QueryString["CustID"].ToString());
        }
    }

    protected void Grid3_RowCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "UpdateFlow")
        {
            string str = Grid3.DataKeys[e.RowIndex][0].ToString();
            PageContext.RegisterStartupScript(Window1.GetShowReference("CustFlow.aspx?enable=false&CustID=" + Request.QueryString["CustID"].ToString() + "&CustFollow=" + str, "跟进情况"));
        }
    }

    protected void Grid2_RowCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "UpdateMetting")
        {
            string str = Grid2.DataKeys[e.RowIndex][0].ToString();
            PageContext.RegisterStartupScript(Window1.GetShowReference("CustMeet.aspx?enable=false&CustID=" + Request.QueryString["CustID"].ToString() + "&CustMettingID=" + str, "跟进情况"));
        }
    }

    private void ShowInfo(int CustID)
    {
        Ylh.BLL.CustBLL bllc = new Ylh.BLL.CustBLL(DbConnectionStr);
        Ylh.Model.TbCust model = bllc.GetModel(CustID);
        this.CustName.Text = model.CustName;
        this.CompanyName.Text = model.CompanyName;
        this.TelPhone.Text = model.TelPhone;
        this.Industry.Text = model.Industry;
        this.CustAddress.Text = model.CustAddress;
        this.ID.Text = model.ID;
        this.Pwd.Text = model.Pwd;
        this.QQ.Text = model.QQ;
        this.mail.Text = model.mail;
        this.Website.Text = model.Website;

        if (model.ClearTime != null)
        {
            this.ClearTime.Text = model.ClearTime.ToString();
        }

        this.Legal.Text = model.Legal;
    }

    private void LoadFlowData(string CustID)
    {
        CustFollowBLL bllf = new CustFollowBLL(DbConnectionStr);
        if (Request.QueryString["StaffID"] == null)
        {
            Grid3.DataSource = bllf.GetFlowData(CustID, StaffID.ToString());
        }
        else
        {
            Grid3.DataSource = bllf.GetFlowData(CustID, Request.QueryString["StaffID"].ToString());
        }
        

        
        Grid3.DataBind();
    }

    private void LoadMetData(string CustID)
    {
        CustMettingBLL bllm = new CustMettingBLL(DbConnectionStr);

        if (Request.QueryString["StaffID"] == null)
        {
            Grid2.DataSource = bllm.GetMettingInfo(StaffID.ToString(), CustID);
        }
        else
        {
            Grid2.DataSource = bllm.GetMettingInfo(Request.QueryString["StaffID"].ToString(), CustID);
        }

        
        Grid2.DataBind();
    }

    private void LoadOpinion(string CustID)
    {
        CustBLL bll = new CustBLL(DbConnectionStr);

        OpinionHist.Text = bll.GetOpinion(Request.QueryString["CustID"].ToString());

        OpinionHist.EncodeText = false;
    }


    protected void Button1_Click(object sender, EventArgs e)
    {

        if (string.IsNullOrEmpty(TextArea1.Text))
        {
            Alert.Show("请先填写意见");
            return;
        }

        CustBLL bll = new CustBLL(DbConnectionStr);

        bll.UpdateOpinion(TextArea1.Text, Request.QueryString["custID"].ToString(), StaffID);


        OpinionHist.Text = bll.GetOpinion(Request.QueryString["CustID"].ToString());

        OpinionHist.EncodeText = false;

        TextArea1.Text = string.Empty;
    }
}